<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/8/6
  Time: 16:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>开班信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${AppPath}/css/font.css">
    <link rel="stylesheet" href="${AppPath}/css/index.css">
    <script type="text/javascript" src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${AppPath}/js/index.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->

</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="form">
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>专业名称
                </label>
                <div class="layui-input-inline">
                    <select name="majorId" id="majorId" onchange="majorId()">

                    </select>
               </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择专业名称
                </div>
                <label class="layui-form-label" id="majormsg">

                </label>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>班主任
                </label>
                <div class="layui-input-inline">
                    <select name="empId" id="empId" onchange="empId();">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择班主任
                </div>
                <label class="layui-form-label" id="empmsg">

                </label>
            </div>
            <div class="layui-form-item">
                <label for="className" class="layui-form-label">
                    <span class="x-red">*</span>班级名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="className" name="className" required="" lay-verify="className"
                           autocomplete="off" class="layui-input" onblur="clazzName()"/>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>填写班级名称
                </div>
                <label class="layui-form-label" id="classmsg">

                </label>
            </div>
                <div class="layui-form-item">
                    <label for="classStatus" class="layui-form-label">
                        班级状态
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="classStatus" name="classStatus" required="" lay-verify="classStatus"
                               autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        填写班级状态
                    </div>
                </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>院系名称
                </label>
                <div class="layui-input-inline">
                    <select name="deptId" id="deptId" onchange="deptId()">

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>选择院系
                </div>
                <label class="layui-form-label" id="deptmsg">

                </label>
            </div>
            <%--<div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="超级管理员" checked="">
                    <input type="checkbox" name="like1[read]" lay-skin="primary" title="编辑人员">
                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="宣传人员" checked="">
                </div>
            </div>--%>

            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" type="button" lay-filter="add" lay-submit="" id="addBtn">
                    确认开班
                </button>
            </div>
        </form>
    </div>
</div>
<script src="${AppPath}/js/jquery.js"></script>
<script>
   $(function(){

       /*初始化*/
       $.ajax({
           url:"${AppPath}/class/findOne",
           type:"post",
           success: function(data){
               if(data.result){
                   /*专业*/
                   let op ='';
                   op += '<option value="0">请选择专业</option>';
                   $.each(data.majorList,function(index,major){
                       op += '<option value="'+major.majorId+'">'+major.majorName+'</option>';
                   })
                   $("#majorId").html(op);
                   pre();
                   /* 班主任*/
                   let oe ='';
                   oe += '<option value="0">请选择班主任</option>';
                   $.each(data.empList,function(index,emp){
                       oe += '<option value="'+emp.empId+'">'+emp.empName+'</option>';
                   })
                   $("#empId").html(oe);
                   pre();
                   /* 院系*/
                   let od ='';
                   od += '<option value="0">请选择院系</option>';
                   $.each(data.deptList,function(index,dept){
                       od += '<option value="'+dept.deptId+'">'+dept.deptName+'</option>';
                   })
                   $("#deptId").html(od);
                   pre();
               }
           }
       })
       //自定义验证规则

       //监听提交
       $("#addBtn").click(function(){
           if(checkmsg()){
               $.ajax({
                   url:"${AppPath}/class/add",
                   data:$("#form").serialize(),
                   type:"post",
                   success: function(data){
                       if(data.result){
                           layer.msg("开班成功",{time:2000,icon:6},function () {
                               //关闭当前frame
                               xadmin.close();
                               //重新定位到查询页面
                               xadmin.father_reload();
                           })
                       }else{
                           layer.msg("开班失败！",{time:2000,icon:5,shift:6});
                       }
                   }
               })
           }

       })


   })
    /*表单校验*/
   function checkmsg() {
       return majorId()&&empId()&&clazzName()&&deptId();
   }

   function  majorId(){
       let zz = /^[1-9]{1,}$/;
       let majorId = $("#majorId").val();
       let msg = "<font color='red'>专业不能为空</font>";
       let flag=false;
       if (zz.test(majorId)) {
           msg = "<font color='green'>ok</font>";
           flag=true;
       }
       $("#majormsg").html(msg);
       return flag;
   }
   function  empId(){
       let zz = /^[1-9]{1,}$/;
       let empId = $("#empId").val();
       let msg = "<font color='red'>班主任不能为空</font>";
       let flag=false;
       if (zz.test(empId)) {
           msg = "<font color='green'>ok</font>";
           flag=true;
       }
       $("#empmsg").html(msg);
       return flag;
   }
   function  deptId(){
       let zz = /^[1-9]{1,}$/;
       let deptId = $("#deptId").val();
       let msg = "<font color='red'>院系不能为空</font>";
       let flag=false;
       if (zz.test(deptId)) {
           msg = "<font color='green'>ok</font>";
           flag=true;
       }
       $("#deptmsg").html(msg);
       return flag;
   }
   function  clazzName(){
       let zz = /^[a-zA-Z\u2E80-\u9FFF][\u2E80-\u9FFF\w]+$/;
       let className = $("#className").val();
       let msg = "<font color='red'>班级不能为空</font>";
       let flag=false;
       if (zz.test(className)) {
           msg = "<font color='green'>ok</font>";
           flag=true;
       }
       $("#classmsg").html(msg);
       return flag;
   }

/*渲染*/
function pre(){
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;
        form.render();
        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
        form.render();
    });
}

</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>

